package {
	import flash.display.*;
	import flash.events.*;
	import flash.ui.*;
	import flash.geom.*;
	import flash.media.*;
	import flash.text.StaticText;
	import flash.utils.Timer;
	import com.combiform.core.*;
	import com.combiform.harness.Combi_Harness;
	
	public class Main extends MovieClip {
		//globals
		const WIDTH:int=600, HEIGHT:int=300;
		
		//api
		var ioHandler:myIO_Handler;
		var cHarness:Combi_Harness;
		var co:Combine_Obj;

		var debug:Boolean=false;
		
		public function Main(){
			this.addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		function init(e:Event){
			this.removeEventListener(Event.ADDED_TO_STAGE, init);

			//Combiform api ** note that in the released version you probably want to take out the combiharness
			ioHandler = new myIO_Handler(this.stage,true,false);
//			cHarness= new Combi_Harness(this.stage);
//			addChild(cHarness);
			co=new Combine_Obj();

			//listeners
//			cHarness.addEventListener(IR_Event.INPUT, irHandler);
			ioHandler.addEventListener(IR_Event.INPUT, irHandler);
			addEventListener(Event.ENTER_FRAME, onFrame);
		}

		//main loop: ioHandler needs to call frameH so make sure this is in your main loop
		function onFrame(e:Event) : void{
			ioHandler.frameH();
		}
		


		
      //irHandler is how your game will process IR_Events
		function irHandler(e:IR_Event):void{
			switch(e.key){
				case IR_Event.IR_ACTIONBUTTON:
					trace ("Main:"+e.controllerNum+":KNOB e.IR_ACTIONBUTTON val="+e.val)
					break;
				case IR_Event.IR_LEFTBUTTON:
//					trace ("Main:e.IR_LEFTBUTTON val="+e.val)
					break;
				case IR_Event.IR_RIGHTBUTTON:
//					trace ("Main:e.IR_RIGHTBUTTON val="+e.val)
					break;
				case IR_Event.IR_DOWNBUTTON:
//					trace ("Main:e.IR_DOWNBUTTON val="+e.val)
					break;
				case IR_Event.IR_UPBUTTON:
//					trace ("Main:e.IR_UPBUTTON val="+e.val)
					break;
				case IR_Event.IR_PRECOMBINEBUTTON:
//					trace ("Main:e.IR_PRECOMBINEBUTTON val="+e.val)
					break
				case IR_Event.IR_LED:
				case IR_Event.IR_LED1:
				case IR_Event.IR_LED2:
				case IR_Event.IR_LED3:
					ioHandler.sendEvent(e);
					trace("Main sent LED event");
					break;
				case IR_Event.IR_COMBINEBUTTON:
					trace ("Main:e.IR_COMBINEBUTTON")
					break;
				default: break;
			}
		}
		

	}
}